// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/parking/api/ParkParkApi'

import OneClass from '@api/parking/model/ParkReq'
import AddClass from '@api/parking/model/ParkDeviceBindReq'
import EditClass from '@api/parking/model/ParkAreaBindReq'

const DelClass = EditClass

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne({ id, parentId }) {
    const TIP = `查询${parentId === '0' ? '' : '子'}车库详情`
    const DTO = CORE.grpcDTO(OneClass, { parkId: [id] })
    const resp = await CORE.grpc(TIP, CLIENT, 'queryParkDetail', DTO)
    return resp
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '关联监控设备') {
    const DTO = CORE.grpcDTO(AddClass, { ...one, parkId: one.id })
    await CORE.grpc(TIP, CLIENT, 'bindParkDevice', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async edit(one, TIP = `关联${CORE.MAP.REGION}`) {
    const DTO = CORE.grpcDTO(EditClass, { ...one, parkId: one.id })
    await CORE.grpc(TIP, CLIENT, 'bindParkArea', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '清除关联') {
    const DTO = CORE.grpcDTO(DelClass, { parkId: id })
    await CORE.grpc(TIP, CLIENT, 'bindParkArea', DTO)
    return CORE.grpcOK(TIP)
  },
}
